package com.kly.smartbi.model.enums;

import lombok.Getter;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Getter
public enum QuestionSubmitStatusEnum {
    PENDING(0, "待判题"),
    JUDGING(1, "判题中"),
    SUCCESS(2, "成功"),
    FAILURE(3, "失败");

    // 私有final属性确保不可变性
    private final int value;
    private final String text;

    // 私有构造函数强制通过枚举常量实例化
    QuestionSubmitStatusEnum(int value, String text) {
        this.value = value;
        this.text = text;
    }

    // 获取枚举值列表
    private static List<String> getValues() {
        return Stream.of(values()).map(QuestionSubmitStatusEnum::getText).collect(Collectors.toList());
    }

    // 通过value反向获取枚举实例
    public static QuestionSubmitStatusEnum fromValue(int value) {
        for (QuestionSubmitStatusEnum status : values()) {
            if (status.getValue() == value) return status;
        }
        return null;
    }
}